#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys

PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))


#sys.path.append(os.path.join(PROJECT_ROOT,'magdia'))
#print sys.path

from flask.ext.script import Manager, Server
from project.application import app, uploadApp
from project.models import *

manager = Manager(app)
upload_manager = Manager(uploadApp)

if app.config["DEBUG"]:
    manager.add_command("runserver", Server('0.0.0.0', port=7001))
    upload_manager.add_command("runupload", Server('0.0.0.0', port=7002))
else:
    manager.add_command("runserver", Server('127.0.0.1', port=7001))
    upload_manager.add_command("runupload", Server('127.0.0.1', port=7002))

@manager.command
def createall():
    from project.application import upload_db
    upload_db.create_all()

if __name__ == '__main__':
    if sys.argv[-1] == "runupload":    
        upload_manager.run()
    else:
        manager.run() 

